package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark63Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark63 extends BaseMark {

    LayoutWatermark63Binding binding;

    public Mark63(@NonNull Context context) {
        super(context);
    }

    public Mark63(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark63(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark63Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.bottom.getChildCount();
            for (int i = 2; i < n; i++) {
                binding.bottom.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark63Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding1, "custom63", binding.binding1);
        setText(binding.binding2, "title63", binding.title);
        setText(binding.binding5, "desc63", binding.binding4);

        setText(binding.binding7, "time63", binding.binding6);
        setTime(binding.binding7, new SimpleDateFormat("yyyy-MM-dd HH:mm"));

        setText(binding.binding9, "didian63", "在这里", binding.binding8);
        setText(binding.binding11, "weather63", binding.binding10);

        setText(binding.binding13, "height63", binding.binding12);
        setText(binding.binding15, "jingwei63", binding.binding14);
        String s = new EditItem("jingwei63").getStringPoint();
        binding.binding15.setText(s);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("custom63", "自定义文字"));
        list.add(new EditItem("title63", "标题"));
        list.add(new EditItem("desc63", "业务介绍"));
        list.add(new EditItem("time63", "时间", true));
        list.add(new EditItem("didian63", "地点"));
        list.add(new EditItem("weather63", "天气"));
        list.add(new EditItem("height63", "海拔"));
        list.add(new EditItem("jingwei63", "经纬度"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding7, new SimpleDateFormat("yyyy-MM-dd HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
